*This Stata do-file replicates Figure 1 in Patrick J. Egan and Megan Mullin, "US Partisan Polarization on Climate Change: Can Stalemate Give Way to Opportunity?" forthcoming in PS: Political Science and Politics.

*this do-file last updated June 16, 2023.

*see "Egan Mullin Figure 1 replication.txt" in this replication archive for details.



version 16
clear all
set more off
set scheme cleanplots
graph set window fontface "Helvetica"



cd "C:\Users\pje202\Dropbox\p.PS CC polarization\Climate polarization - PS\Replication archive\Figure 1 replication"

************
*CREATE DATASET
************


import delimited "2021-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) 
gen year = 2021
keep district- lifetimescore repealingassaultonmethanepolluti investinginclimatesmartandprowil buildingclimateresilientwastewat investingintransportationandwate proenvironmentfundingpackage247 transformativeclimatejobsandjust v29 year
save "lcv cc votes in house.dta", replace

import delimited "2020-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2020

keep district- lifetimescore emergencyandclimatedisasteraidfo investinginclimateambitiousinfra year
append using "lcv cc votes in house.dta"
save "lcv cc votes in house.dta", replace

import delimited "2019-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year=2019

keep district- lifetimescore year recognizingtheneedforclimatejust addressingclimatechangesdamages1  keepingamericascommitmenttothepa ignoringthecostsofclimatechange3 boostingcleanenergyandclimatefun stoppingcarbonpollutionlimitsfor blockingtheepafromreducingcarbon methanepollutionsafeguards385 proenvironmentfundingbill408 usmcatradedeal701

ren ignoringthecostsofclimatechange3 ignoring362

append using "lcv cc votes in house.dta"
save "lcv cc votes in house.dta", replace
import delimited "2018-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2018

keep district- lifetimescore year delayingpublichealthprotections9 underminingcleanairstandards101 localconsentofnuclearwastetranpo nuclearstorage179 methanepollutionsafeguards346 ignoringthecostsofclimatechange3 anticlimatesolutionsresolution36 minimizingmethanepollution390 underminingnepareview392
append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2017-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2017

keep district- lifetimescore year extremeassaultonthemethaneandwas nationalsecuritythreatofclimatec attackonsmogprotectionsthecleana protectingstrongozonestandards47 methanepollutionsafeguards488 recognizingthecostofclimatechang

*this vote has same varname as vote in next dataset, so renaming:
ren recognizingthecostofclimatechang recognizingthecost489


append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2016-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2016
keep district- lifetimescore year militaryresiliencetoclimatechang methanepollutionfromdrillingonpu carbonpollution431 recognizingthecostofclimatechang methanepollutionsafeguards434
append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2015-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2015
keep district- lifetimescore year carbonpollutionlimitsforpowerpla socialcostofcarbon400 climatechangeresilienceadaptatio extremeattackoncarbonpollutionli v39
append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2014-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2014
keep district- lifetimescore year climatechangeandpubliclands39 underminingfloodinsurancereform9 climatechangescience103 carbonpollution106 blockingclimateactionintradeagre socialcostofcarbon389 impactsofclimatechange397 bigpollutergiveaway515 keystonexltarsandspipelinekxl519
append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2013-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2013
keep district- lifetimescore year resiliencyindisasterrelief22 keystonexltarsandspipelinekxl179 restrictionondirtyfuels394 socialcostofcarbon430 methaneemissions601
append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2012-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2012
keep district- lifetimescore year drillingeverywheretofundtranspor environmentalassaultinthetranspo climatechangeeducation241 keystonexltarsandspipeline292 carbonpollutionendangermentfindi broadenvironmentalassault603
append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2011-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7)  clear
gen year = 2011
keep district- lifetimescore year sweepingenvironmentalfundingandp globalwarmingpollution249 climatechangeadaption448 keystonexltarsandspipeline650

append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2010-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2010
keep district- lifetimescore year dirtyairactcosponsorship0 algalbloomreduction109 estuaryprotection209 oceanacidificationprevention341

append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2009-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2009
keep district- lifetimescore year climatechangeandcleanenergy477 climatechangeandcleanenergy2xsco defundingenvironmentalandenergys

append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace

import delimited "2007-house-scorecard-grid-export.csv", delimiter(comma) varnames(7) encoding(UTF-8) rowrange(7) clear
gen year = 2007
keep district- lifetimescore year liquidcoal91 globalwarmingandnationalsecurity reducingglobalwarming555 energylegislationfuelefficiencya v22 v25

append using "lcv cc votes in house.dta", force
save "lcv cc votes in house.dta", replace


***********************
*CLEAN DATA AND CREATE COLLAPSED DATASET FOR GRAPHING
***********************

order year party district
drop bioid govtrackid 

*create numerical vars for each of 81 votes:

for num 1(1)81: gen vote_X=.
for var liquidcoal91- v29 \ num 1(1)81: replace vote_Y = 1 if X=="+"
for var liquidcoal- v29 \ num 1(1)81: replace vote_Y = 0 if X=="-"

*gen year-by-year means:

egen score_2021 = rowmean(vote_75-vote_81)
egen score_2020 = rowmean(vote_73-vote_74)
egen score_2019 = rowmean(vote_63-vote_72)
egen score_2018 = rowmean(vote_54-vote_62)
egen score_2017 = rowmean(vote_48-vote_53)
egen score_2016 = rowmean(vote_43-vote_47)
egen score_2015 = rowmean(vote_38-vote_42)
egen score_2014 = rowmean(vote_29-vote_37)
egen score_2013 = rowmean(vote_24-vote_28)
egen score_2012 = rowmean(vote_18-vote_23)
egen score_2011 = rowmean(vote_14-vote_17)
egen score_2010 = rowmean(vote_10-vote_13)
egen score_2009 = rowmean(vote_7-vote_9)
egen score_2007 = rowmean(vote_1-vote_6)

save, replace


collapse (mean) score_*, by(party)
reshape long score_, i(party) j(year)
for var score_*: ren X Xmean
save lcv_means.dta, replace

use "lcv cc votes in house.dta", clear
collapse (p10) score_*, by(party)
reshape long score_, i(party) j(year)
for var score*: rename X Xp10
save lcv_p10s.dta, replace

use "lcv cc votes in house.dta"
collapse (p90) score_*, by(party)
reshape long score_, i(party) j(year)
for var score*: rename X Xp90
save lcv_p90s.dta, replace

merge 1:1 party year using "lcv_p10s.dta", nogenerate
merge 1:1 party year using "lcv_means.dta", nogenerate

for var score*: replace X = X*100

save lcv_summary.dta, replace


***********************
*CREATE FIGURE 1
***********************

twoway (rarea score_p10 score_p90 year if party=="D", sort fcolor(ltblue%50) lcolor(ltblue%50)) (rarea score_p10 score_p90 year if party=="R", sort fcolor(pink%10) lcolor(pink%10)) (connected score_mean year if party=="D", mc(blue) lc(blue) ms(o)) (connected score_mean year if party=="R", mc(red) lc(red) ms(o)) , xlabel(2007(2)2021) ytitle("mean LCV score on" "climate change-related votes") scheme(cleanplots) legend(order(3 1 4 2) label(3 Democratic mean score) label(4 Republican mean score) label(1 "10th-90th %ile range") label(2 "10th-90th %ile range")) xtitle("")

graph export Figure1.tif, as(tif) width(3000) replace

***********************
*CREATE FIGURE 1 - grayscale
***********************

twoway (rarea score_p10 score_p90 year if party=="D", sort fcolor(gs7%50) lcolor(gs7%50)) (rarea score_p10 score_p90 year if party=="R", sort fcolor(gs7%10) lcolor(gs7%10)) (connected score_mean year if party=="D", mc(black) lc(black) ms(o)) (connected score_mean year if party=="R", mc(gs9) lc(gs9) ms(o)) , xlabel(2007(2)2021) ytitle("mean LCV score on" "climate change-related votes") scheme(cleanplots) legend(order(3 1 4 2) label(3 Democratic mean score) label(4 Republican mean score) label(1 "10th-90th %ile range") label(2 "10th-90th %ile range")) xtitle("")

graph export Figure1_gs.tif, as(tif) width(3000) replace

